﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EGuayas.Web.Resources;
using EntGuayasSLA.BL;
using EntGuayasSLA.BL.Archivos.Pdf;
using EntGuayasSLA.BL.Listas;
using Ext.Net;
using EntGuayasSLA.BL.Listas.Criterias;

namespace EGuayas.Web.Licenciamiento.dma.tabs
{
    public partial class pgAnexos : pgBase
    {
        protected string  PageId
        {
            get
            {
                try
                {

                    return (Session["PageId"].ToString());
                }
                catch (Exception ex)
                {
                    X.Msg.Show(new MessageBoxConfig
                    {
                        Title = Titulos.TituloAviso,
                        Message = "Su sessión ha expirado, ingrese nuevamente",
                        Buttons = MessageBox.Button.OK,
                        Icon = MessageBox.Icon.WARNING
                    });
                   
                }
                return "";
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!X.IsAjaxRequest)
                {               
                    Session["PageId"] = Request["idx"];
                }
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
        }
        #region Expander Grid
        protected static void GrdSubDoc_Command(object sender, DirectEventArgs e)
        {
            try
            {
                /*
                    string commandName = e.ExtraParams["command"];
                    long Id = Convert.ToInt64(e.ExtraParams["Id"]);
                */
            }
            catch 
            {
                //RegistrarLog(ex);
            }
        }
        [DirectMethod]
        public static string GetSubDoc(Dictionary<string, string> parameters)
        {
            try
            {
            ArchivoSubArchivosCriteria criteria = ArchivoSubArchivosCriteria.NewArchivoSubArchivosCriteria();
            criteria.Id = parameters["id"];
            criteria.Tabla = Valores.Modulo_Archivo_Licenciamiento;

            var data = ArchivoLista.GetArchivoLista(criteria);

            if (data.Count != 0)
            {
                /*
                    <ext:ModelField Name="FaseLicId" Type="String" />
                    <ext:ModelField Name="FechaCreacion" Type="Date" />
                    <ext:ModelField Name="FechaFirmado" Type="Date" />
                    <ext:ModelField Name="Firmado" Type="String" />
                    <ext:ModelField Name="Id" Type="String" />
                    <ext:ModelField Name="Descripcion" Type="String" />
                    <ext:ModelField Name="Nombre" Type="String" />
                    <ext:ModelField Name="PersonaId" Type="String" />
                    <ext:ModelField Name="PersonaNombres" Type="String" />
                    <ext:ModelField Name="Referencia" Type="String" />
                    <ext:ModelField Name="RequiereFirmar" Type="String" />
                    <ext:ModelField Name="Ruta" Type="String" />
                    <ext:ModelField Name="TipoDocumento" Type="String" />
                    <ext:ModelField Name="Version" Type="Int" />
           
                 */
                GridPanel grid = new GridPanel
                {
                    Height = 90,
                    EnableColumnHide = false,
                    Store = 
                    { 
                        new Store 
                        { 
                            Model = {
                                new Model {
                                    IDProperty = "Id",
                                    Fields = 
                                    {
                                        new ModelField("Id"),
                                        new ModelField("Nombre"),
                                        new ModelField("Descripcion"),
                                        new ModelField("FechaCreacion"),
                                        new ModelField("Version"),
                                        new ModelField("Ruta")
                                    }
                                }
                            },
                            DataSource = data
                        }
                    },
                    ColumnModel =
                    {
                        Columns = { }
                    },

                };


                Column addColumn1 = new Column();
                addColumn1.Text = "Nombre";
                addColumn1.DataIndex = "Nombre";
                addColumn1.Flex = 4;
                grid.ColumnModel.Columns.Add(addColumn1);

                Column addColumn2 = new Column();
                addColumn2.Text = "Descripción";
                addColumn2.DataIndex = "Descripcion";
                addColumn2.Flex = 4;
                grid.ColumnModel.Columns.Add(addColumn2);

                Column addColumn3 = new Column();
                addColumn3.Text = "Fecha";
                addColumn3.DataIndex = "FechaCreacion";
                addColumn3.Flex = 4;
                grid.ColumnModel.Columns.Add(addColumn3);

                Column addColumn4 = new Column();
                addColumn4.Text = "Versión";
                addColumn4.DataIndex = "Version";
                addColumn4.Flex = 4;
                grid.ColumnModel.Columns.Add(addColumn4);

                CommandColumn commandColumn = new CommandColumn();
                commandColumn.ID = "colAction" + System.Guid.NewGuid();
                commandColumn.Flex = 1;
                //commandColumn.Text = "Visualizar";
                commandColumn.DataIndex = "Id";
                commandColumn.Commands.Add(new GridCommand { Icon = Ext.Net.Icon.Zoom, CommandName = "View", Text = "Vizualizar" });
                commandColumn.Listeners.Command.Handler="AppGlobalJs.showPdf('../../..',record.data.Ruta);";
              

                //commandColumn.DirectEvents.Command.Event += GrdSubDoc_Command;
                //commandColumn.DirectEvents.Command.ExtraParams.Add(new Parameter { Name = "Id", Value = "record.data.Id" });
                //commandColumn.DirectEvents.Command.ExtraParams.Add(new Parameter { Name = "command", Value = "command" });
                 grid.ColumnModel.Columns.Add(commandColumn);
                return ComponentLoader.ToConfig(grid);
            }
            }
            catch 
            {
                //RegistrarLog(ex);
            }
            return null;
        }
        #endregion Expander Grid
        [DirectMethod]
        public ArchivoLista BindData()
        {
            try
            {
                    if (PageId != "")
                    {
                        //::Todo anexos
                        //return ArchivoLista.GetArchivoLista(PageId);
                        return null;
                    }
                    else
                    {
                        return null;
                    }
            }
            catch (Exception ex)
            {
                RegistrarLog(ex);
            }
            return null;
        }
       
     
        [DirectMethod]
        public static string GetGrid(Dictionary<string, string> parameters)
        {
            // string id = parameters["id"];

            List<object> data = new List<object>();

            for (int i = 1; i <= 10; i++)
            {
                data.Add(new { ID = "P" + i, Name = "Product " + i, Desc = "Product " + i, Fech = "" + DateTime.Now.ToLongTimeString(), Version = "Product " + i });
            }

            GridPanel grid = new GridPanel
            {
                Height = 90,
                EnableColumnHide = false,
                Store = 
            { 
                new Store 
                { 
                    Model = {
                        new Model {
                            IDProperty = "ID",
                            Fields = 
                            {
                                new ModelField("ID"),
                                new ModelField("Name"),
                                new ModelField("Desc"),
                                new ModelField("Fech"),
                                new ModelField("Version")
                              
                            }
                        }
                    },
                    DataSource = data
                }
            },
                ColumnModel =
                {
                    Columns =  {}
                },

            };


            Column addColumn1 = new Column();
            addColumn1.Text = "Nombre";
            addColumn1.DataIndex = "Nombre";
            addColumn1.Flex = 4;
            grid.ColumnModel.Columns.Add(addColumn1);

            Column addColumn2 = new Column();
            addColumn2.Text = "Descripción";
            addColumn2.DataIndex = "Desc";
            addColumn2.Flex = 4;
            grid.ColumnModel.Columns.Add(addColumn2);

            Column addColumn3 = new Column();
            addColumn3.Text = "Fecha";
            addColumn3.DataIndex = "Fech";
            addColumn3.Flex = 4;
            grid.ColumnModel.Columns.Add(addColumn3);

            Column addColumn4 = new Column();
            addColumn4.Text = "Versión";
            addColumn4.DataIndex = "Version";
            addColumn4.Flex = 4;
            grid.ColumnModel.Columns.Add(addColumn4);

            CommandColumn commandColumn = new CommandColumn();
            commandColumn.ID = "colAction" + System.Guid.NewGuid();
            commandColumn.Flex = 1;
            //commandColumn.Text = "Visualizar";
            commandColumn.DataIndex = "Id";
            commandColumn.Commands.Add(new GridCommand { Icon = Ext.Net.Icon.Zoom, CommandName = "View", Text = "Vizualizar" });
            commandColumn.Listeners.Command.Handler = "AppGlobalJs.showPdf('../../..',record.data.Ruta);";
            grid.ColumnModel.Columns.Add(commandColumn);
            return ComponentLoader.ToConfig(grid);
        }
       
   
    }


}